<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>索引地理形状 | Elasticsearch: 权威指南 | Elastic</title>
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
</head>
<body>
<div class="main-container">
    <section id="content">
        
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原文地址: <a href="https://www.elastic.co/guide/cn/elasticsearch/guide/current/indexing-geo-shapes.html" rel="nofollow">https://www.elastic.co/guide/cn/elasticsearch/guide/current/indexing-geo-shapes.html</a>, 版权归 www.elastic.co 所有<br/>
                            英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/guide/current/indexing-geo-shapes.html" rel="nofollow">https://www.elastic.co/guide/en/elasticsearch/guide/current/indexing-geo-shapes.html</a>
                            </div>
                        <!-- start body -->
                  <div class="page_header">
<b>请注意:</b><br>本书基于 Elasticsearch 2.x 版本，有些内容可能已经过时。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch: 权威指南</a></span>
»
<span class="breadcrumb-link"><a href="geoloc.html">地理位置</a></span>
»
<span class="breadcrumb-link"><a href="geo-shapes.html">地理形状</a></span>
»
<span class="breadcrumb-node">索引地理形状</span>
</div>
<div class="navheader">
<span class="prev">
<a href="mapping-geo-shapes.html">« 映射地理形状</a>
</span>
<span class="next">
<a href="querying-geo-shapes.html">查询地理形状 »</a>
</span>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="indexing-geo-shapes"></a>索引地理形状 (Indexing Geo Shapes)<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elasticsearch-cn/elasticsearch-definitive-guide/edit/cn/340_Geoshapes/74_Indexing_geo_shapes.asciidoc">edit</a>
</h2>
</div></div></div>
<p>地理形状通过 <a href="http://geojson.org/" class="ulink" target="_top">GeoJSON</a> 来表示，这是一种开放的使用 JSON 实现的二维形状编码方式。
每个形状都包含了形状类型: <code class="literal">点(point)</code>, <code class="literal">线(line)</code>, <code class="literal">多边形(polygon)</code>, <code class="literal">包络面(envelope)</code>, 以及一个或多个经纬度坐标集合的数组。</p>
<div class="caution admon">
<div class="icon"></div>
<div class="admon_content">
<p>在 GeoJSON 里，经纬度表示方式通常是 <em>纬度</em> 在前， <em>经度</em> 在后。</p>
</div>
</div>
<p>如，我们用一个多边形(polygon )来索引阿姆斯特丹的达姆广场：</p>
<div class="pre_wrapper lang-json">
<pre class="programlisting prettyprint lang-json">PUT /attractions/landmark/dam_square
{
    "name" : "Dam Square, Amsterdam",
    "location" : {
        "type" : "polygon", <a id="CO244-1"></a><i class="conum" data-value="1"></i>
        "coordinates" : [[ <a id="CO244-2"></a><i class="conum" data-value="2"></i>
          [ 4.89218, 52.37356 ],
          [ 4.89205, 52.37276 ],
          [ 4.89301, 52.37274 ],
          [ 4.89392, 52.37250 ],
          [ 4.89431, 52.37287 ],
          [ 4.89331, 52.37346 ],
          [ 4.89305, 52.37326 ],
          [ 4.89218, 52.37356 ]
        ]]
    }
}</pre>
</div>
<div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO244-1"><i class="conum" data-value="1"></i></a></p>
</td>
<td align="left" valign="top">
<p><code class="literal">type</code> 参数指明了经纬度坐标集表示的形状类型: 多边形(polygon)。</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO244-2"><i class="conum" data-value="2"></i></a></p>
</td>
<td align="left" valign="top">
<p><code class="literal">lon/lat</code> 列表描述了多边形的形状。</p>
</td>
</tr>
</table>
</div>
<p>上例中大量的方括号可能看起来让人困惑，不过实际上 GeoJSON 的语法非常简单：</p>
<div class="olist orderedlist">
<ol class="orderedlist">
<li class="listitem">
<p>用一个数组表示 <code class="literal">经纬度</code> 坐标点：</p>
<pre class="literallayout">[lon,lat]</pre>

</li>
<li class="listitem">
<p>一组坐标点放到一个数组来表示一个多边形：</p>
<pre class="literallayout">[[lon,lat],[lon,lat], ... ]</pre>

</li>
<li class="listitem">
<p>一个多边形(<code class="literal">polygon</code>)可以包含多个多边形；第一个表示多边形的外轮廓，后续的多边形表示第一个多边形内部的空洞：</p>
<pre class="literallayout">[
  [[lon,lat],[lon,lat], ... ],  # main polygon
  [[lon,lat],[lon,lat], ... ],  # hole in main polygon
  ...
]</pre>

</li>
</ol>
</div>
<p>参见 <a href="https://www.elastic.co/guide/en/elasticsearch/reference/5.6/geo-shape.html" class="ulink" target="_top">Geo-shape mapping documentation</a> 了解更多支持的形状。</p>
</div>
<div class="navfooter">
<span class="prev">
<a href="mapping-geo-shapes.html">« 映射地理形状</a>
</span>
<span class="next">
<a href="querying-geo-shapes.html">查询地理形状 »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>